package com.gwtjs.icustom.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gwtjs.icustom.controller.install.SetSystemController;
import com.gwtjs.icustom.pojo.ServerHost;

public class Validate {
	
	private final static Logger logger = LoggerFactory.getLogger(SetSystemController.class);
	
	/**
	 * <h2>主机是否存在
	 * @param host
	 * @return
	 */
	public static boolean hostIs(ServerHost host) {
		boolean flag = true;
		String cmd = "ping -c 2 "+host.getHostIp();
		
		logger.info("\nping cmd ：{}" , cmd);
		return flag;
	}
	
	/**
	 * <h2>docker是否安装
	 * @param host
	 * @return
	 */
	public static boolean dockerIsInstall(ServerHost host) {
		boolean flag = true;
		String cmd = "docker -v";

		logger.info("\nping cmd ：{}" , cmd);
		return flag;
	}
	
	/**
	 * <h2>mysql是否安装
	 * @param host
	 * @return
	 */
	public static boolean mysqlIsInstall(ServerHost host) {
		boolean flag = true;
		String cmd = "docker ps -a";

		logger.info("\nping cmd ：{}" , cmd);
		return flag;
	}
	
	/**
	 * <h2>apache httpd是否安装
	 * @param host
	 * @return
	 */
	public static boolean httpdIsInstall(ServerHost host) {
		boolean flag = true;
		String cmd = "docker ps -a";

		logger.info("\nping cmd ：{}" , cmd);
		return flag;
	}
	
	/**
	 * <h2>jdk是否安装
	 * @param host
	 * @return
	 */
	public static boolean jdkIsInstall(ServerHost host) {
		boolean flag = true;
		String cmd = "java -version";

		logger.info("\nping cmd ：{}" , cmd);
		return flag;
	}
	
	/**
	 * <h2>ntpd是否安装
	 * @param host
	 * @return
	 */
	public static boolean ntpdIsInstall(ServerHost host) {
		boolean flag = true;
		String cmd = "ntpd -v";
		String result = null;
		ShellUtil execute = new ShellUtil(host.getHostIp(), host.getAccount(), host.getPassword(), host.getHostPort());
		result = execute.executeForResult(cmd);
		logger.info("\ndocker Is Install cmd ：{}" , result);
		return flag;
	}
	
	/**
	 * <h2>ambari是否安装
	 * @param host
	 * @return
	 */
	public static boolean ambariIsInstall(ServerHost host) {
		boolean flag = true;
		String cmd = "ambari-server -v";
		String result = null;
		ShellUtil execute = new ShellUtil(host.getHostIp(), host.getAccount(), host.getPassword(), host.getHostPort());
		result = execute.executeForResult(cmd);
		logger.info("\ndocker Is Install cmd ：{}" , result);
		return flag;
	}
	
}
